﻿@model LynxWiki.Models.AllUsersAndRoles
@using LynxWiki.Models

@{
    ViewBag.Title = "Manage Users and Roles";
}

<h2>Manage Users and Roles</h2>
<table class="TableClass">
    <tr>
        <th class="TableCellHighlighted">User Name</th>
        <th class="TableCellHighlighted" colspan="4">Actions</th>
    </tr>
    @foreach (UserProfile user in Model.Users) {
      <tr>
        <td class="TableCell">@user.UserName</td>
        <td class="TableCell">
            @using (Html.BeginForm("ListUserRoles", "UserRoles", FormMethod.Post, new { @class = "frmListUserRoles", id = user.UserId + "_frmListUserRoles" })) {
                @Html.Hidden("UserId", user.UserId)
                @Html.Hidden("UserName", user.UserName)
                <input type="submit" name="btnListUserRoles" class="btnListUserRoles" value="List User Roles" />
            }
        </td>
        <td class="TableCell">
            @using (Html.BeginForm("ListUserMissingRoles", "UserRoles", FormMethod.Post, new { @class = "frmAddRoleToUser", id = user.UserId + "_frmAddRoleToUser" })) {
                @Html.Hidden("UserId", user.UserId)
                @Html.Hidden("UserName", user.UserName)
                <input type="submit" name="btnAddRoleToUser" class="btnAddRoleToUser" value="Add Role To User" />
            }
        </td>
        <td class="TableCell">
            @using (Html.BeginForm("ListUserRoles", "UserRoles", FormMethod.Post, new { @class = "frmRemoveRoleFromUser", id = user.UserId + "_frmRemoveRoleFromUser" })) {
                @Html.Hidden("UserId", user.UserId)
                @Html.Hidden("UserName", user.UserName)
                <input type="submit" name="btnRemoveRoleFromUser" class="btnRemoveRoleFromUser" value="Remove Role From User" />
            }
        </td>
        <td class="TableCell">
            @using (Html.BeginForm("DeleteUser", "UserRoles", FormMethod.Post, new { @class = "frmDeleteUser", id = user.UserId + "_frmDeleteUser" })) {
                @Html.Hidden("UserId", user.UserId)
                @Html.Hidden("UserName", user.UserName)
                <input type="submit" name="btnDeleteUser" class="btnDeleteUser" value="Delete User" />
            }
        </td>
      </tr>
    }
</table><br />
<br />
            @using (Html.BeginForm("AddRole", "UserRoles", FormMethod.Post, new { @class = "frmAddRole", id = "frmAddRole" })) {
                <input type="text" id="newRole" name="newRole" />
                <input type="submit" name="btnAddRole" class="btnAddRole" value="Add Role" />
            }

<br />
<table class="TableClass">
    <tr>
        <th class="TableCellHighlighted">Role Name</th>
        <th class="TableCellHighlighted" colspan="2">Actions</th>
    </tr>
    @foreach (string role in Model.AppRoles) {
      <tr>
        <td class="TableCell">@role</td>
        <td class="TableCell">
            @using (Html.BeginForm("ListUsersInRole", "UserRoles", FormMethod.Post, new { @class = "frmListUsersInrole", id = role + "_frmListUsersInrole" })) {
                @Html.Hidden("Role", role)
                <input type="submit" name="btnListUsersInRole" class="btnListUsersInRole" value="List Users In Role" />
            }
        </td>
        <td class="TableCell">
            @using (Html.BeginForm("RemoveRole", "UserRoles", FormMethod.Post, new { @class = "frmRemoveRole", id = role + "_frmRemoveRole" })) {
                @Html.Hidden("Role", role)
                <input type="submit" name="btnRemoveRole" class="btnRemoveRole" value="Remove Role" />
            }
        </td>
      </tr>
    }
</table>